<ix-modal-header
  title="NFS"
  [requiredRoles]="requiredRoles"
  [loading]="isFormLoading()"
></ix-modal-header>

<mat-card class="card">
  <mat-card-content>
    <form class="ix-form-container" [formGroup]="form" (submit)="onSubmit()">
      <ix-fieldset [title]="'General Options' | translate">
        <ix-select
          formControlName="bindip"
          [label]="'Bind IP Addresses' | translate"
          [options]="ipChoices$"
          [multiple]="true"
          [tooltip]="tooltips.bindip | translate"
        ></ix-select>

        <ix-checkbox
          formControlName="servers_auto"
          [label]="'Calculate number of threads dynamically' | translate"
          [tooltip]="tooltips.servers_auto | translate"
        ></ix-checkbox>

        @if (!form.controls.servers_auto.value) {
          <ix-input
            formControlName="servers"
            type="number"
            [label]="'Specify number of threads manually' | translate"
            [required]="true"
            [tooltip]="tooltips.servers | translate"
          ></ix-input>
        }
      </ix-fieldset>

      <div class="two-columns">
        <ix-fieldset [title]="'NFSv4' | translate">
          <ix-select
            formControlName="protocols"
            [label]="'Enabled Protocols' | translate"
            [options]="protocolOptions$"
            [multiple]="true"
            [tooltip]="tooltips.protocols | translate"
            [required]="true"
          ></ix-select>

          <ix-input
            formControlName="v4_domain"
            [label]="'NFSv4 DNS Domain' | translate"
            [tooltip]="tooltips.v4_domain | translate"
          ></ix-input>

          <ix-checkbox
            formControlName="v4_krb"
            [label]="'Require Kerberos for NFSv4' | translate"
            [tooltip]="tooltips.v4_krb | translate"
          ></ix-checkbox>
        </ix-fieldset>
        <ix-fieldset [title]="'Ports' | translate">
          <ix-input
            formControlName="mountd_port"
            type="number"
            [label]="'mountd(8) bind port' | translate"
            [tooltip]="tooltips.mountd_port | translate"
          ></ix-input>

          <ix-input
            formControlName="rpcstatd_port"
            type="number"
            [label]="'rpc.statd(8) bind port' | translate"
            [tooltip]="tooltips.rpcstatd_port | translate"
          ></ix-input>

          <ix-input
            formControlName="rpclockd_port"
            type="number"
            [label]="'rpc.lockd(8) bind port' | translate"
            [tooltip]="tooltips.rpclockd_port | translate"
          ></ix-input>
        </ix-fieldset>
      </div>

      <ix-fieldset [title]="'Other Options' | translate">
        <ix-checkbox
          formControlName="rdma"
          [label]="'Enable NFS over RDMA' | translate"
        ></ix-checkbox>

        <ix-checkbox
          formControlName="allow_nonroot"
          [label]="'Allow non-root mount' | translate"
          [tooltip]="tooltips.allow_nonroot | translate"
        ></ix-checkbox>

        <ix-checkbox
          formControlName="userd_manage_gids"
          [label]="'Manage Groups Server-side' | translate"
          [tooltip]="tooltips.userd_manage_gids | translate"
        ></ix-checkbox>
      </ix-fieldset>

      <ix-form-actions>
        <div>
          <button
            *ixRequiresRoles="requiredRoles"
            mat-button
            type="submit"
            color="primary"
            ixTest="save"
            [disabled]="form.invalid || isFormLoading()"
          >
            {{ 'Save' | translate }}
          </button>
        </div>
        <div class="add-spn-container">
          @if (isAddSpnVisible && isAddSpnDisabled()) {
            <ix-tooltip
              [header]="'Add SPN' | translate"
              [message]="'Save the \'Require Kerberos for NFSv4\' value before adding SMP' | translate"
            ></ix-tooltip>
          }
          @if (isAddSpnVisible) {
            <ng-container *ixRequiresRoles="requiredRoles">
              <button
                mat-button
                type="button"
                color="primary"
                ixTest="add-spn"
                [disabled]="isAddSpnDisabled()"
                (click)="addSpn()"
              >
                {{ 'Add SPN' | translate }}
              </button>
            </ng-container>
          }
        </div>
      </ix-form-actions>
    </form>
  </mat-card-content>
</mat-card>
